<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1.0" name="viewport">
    <title>黑名单</title>
    <link href="../../resource/css/bootstrap.min.css?v=3.3.5" rel="stylesheet"
          th:href="@{/resource/css/bootstrap.min.css?v=3.3.5}"/>
    <link href="../../resource/css/font-awesome.min.css?v=4.4.0" rel="stylesheet"
          th:href="@{/resource/css/font-awesome.min.css?v=4.4.0}"/>
    <!-- Morris -->
    <link href="../../resource/css/animate.min.css" rel="stylesheet" th:href="@{/resource/css/animate.min.css}"/>

    <link href="../../resource/hotui/css/style.min-1.0.8.css" th:href="@{/resource/hotui/css/style.min-1.0.8.css}"
          rel="stylesheet">
    <link href="../../resource/hotui/css/hotui.style.override.css"
          rel="stylesheet" th:href="@{/resource/hotui/css/hotui.style.override.css}"/>
    <link href="../../resource/css/style-diy.css?v=4.0.0" rel="stylesheet"
          th:href="@{/resource/css/style-diy.css?v=4.0.0}"/>
    <link href="../../resource/hotui/js/plugins/datetimepick/css/daterangepicker.css"
          rel="stylesheet" th:href="@{/resource/hotui/js/plugins/datetimepick/css/daterangepicker.css}"/>


    <style>
        /*.daterangepicker {*/
        /*    z-index: 999999999 !important;*/
        /*}*/
        .form-group-box {
            display: inline-block;
            width: 200px;
        }
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <!--search-->
    <form class="search-panel" id="searchForm" method="get" role="form" th:object="${condition}">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox">
                    <div class="ibox-content">
                        <div class="form-inline">
                            <input name="pageIndex" th:value="${pageIndex}" type="hidden"/>
                            <input name="type" th:value="*{type}" type="hidden"/>
                            <div class="form-inline">
                                <div class="form-group m-r-sm">
                                    <label class=" control-label" for="keyword">关键字：</label>
                                    <input class="form-control input-sm mb10" id="keyword" name="keyword"
                                           placeholder="用户手机/昵称"
                                           style="width: 156px;" th:value="*{keyword}" type="text"/>
                                </div>
                                <div class="form-group m-r-sm">
                                    <button class="btn btn-primary btn-sm m-b-none searchBtn"
                                            onclick="listHandler.search(1)"
                                            type="button">筛选
                                    </button>
                                    <button class="btn btn-primary btn-sm m-b-none" onclick="listHandler.searchAll()"
                                            type="button">显示全部
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <!--search-->


    <!--list-->
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins m-b-none">
                <div class="tabs-container" style="margin-top: 20px;">
                    <ul class="nav nav-tabs">
                        <li class="active" th:class="${condition.type==0?'active':''}">
                            <a th:href="@{/blacklist/list(type=0)}" href="../blacklist/list.html">直播间黑名单</a>
                        </li>
                        <li th:class="${condition.type==1?'active':''}">
                            <a th:href="@{/blacklist/list(type=1)}"
                               href="../blacklist/list.html">购买黑名单</a>
                        </li>
                    </ul>
                </div>
                <div class="tabs-container">
                    <div class="tab-content">
                        <div class="tab-pane active">
                            <div class="panel-body table-responsive">
                                <div class="form-inline" style="padding-bottom: 15px;text-align: right;">
                                    <button type="button" onclick="listHandler.createModalShow()"
                                            class="btn btn-primary btn-sm m-b-none">添加黑名单
                                    </button>
                                </div>
                                <table class="table table-bordered table-hover table-center">
                                    <thead>
                                    <tr>
                                        <th>序号</th>
                                        <th>用户</th>
                                        <th>创建时间</th>
                                        <th width="150">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr th:each="item,stat:${list}">
                                        <td th:text="${stat.count}">1</td>
                                        <td>
                                            <span th:text="${item.user.nickName}">昵称</span>
                                            <span th:text="${item.user.mobile}">152****1234</span>
                                        </td>
                                        <td th:text="${#temporals.format(item.createTime,'yyyy-MM-dd HH:mm:ss')}"></td>
                                        <td style="text-align: center">
                                            <button class="btn btn-default btn-xs m-b-none"
                                                    th:onclick="listHandler.delete([[${item.id}]])"
                                                    type="button">移除黑名单
                                            </button>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                                <p style="float: left; margin: 20px 0;">
                                    共<span th:text="${totalRecords}"></span>条记录，当前第<span th:text="${pageIndex}"></span>/<span
                                        th:text="${totalPages==0?1:totalPages}"></span>，每页20条记录
                                </p>
                                <ul class="pagination pagination-split" style="float: right;">
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="create_video_template">
    <div class="form-horizontal" style="width: 400px;">
        <div class="form-group">
            <label class="col-sm-4 control-label">目标手机号:</label>
            <div class="col-sm-5 form-group-box" style="display: inline-block">
                <input id="targetMobile" type="number" class="form-control" placeholder="用户手机号">
            </div>
        </div>
    </div>
</script>

<!--基础框架js-->
<script src="../../resource/js/jquery.min2.2.4.js?v=2.1.4" th:src="@{/resource/js/jquery.min2.2.4.js?v=2.1.4}"></script>
<script src="../../resource/js/bootstrap.min.js?v=3.3.5" th:src="@{/resource/js/bootstrap.min.js?v=3.3.5}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-utils.js"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-utils.js?v=1.0.0}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-init.js"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-init.js}"
></script>
<script src="../../resource/lib/moment.min.js" th:src="@{/resource/lib/moment.min.js}"></script>
<script src="../../resource/hotui/js/plugins/datetimepick/js/daterangepicker.js"
        th:src="@{/resource/hotui/js/plugins/datetimepick/js/daterangepicker.js}"></script>


<script th:inline="javascript" type="text/javascript">
    const pageIndex = /*[[${pageIndex}]]*/  1;
    const totalPages = /*[[${totalPages}]]*/  1;
    const pageUri = /*[[@{/blacklist/list}]]*/  "";
    const apiUri = /*[[@{/blacklist/list}]]*/  "";
    const blacklistType =/*[[${condition.type}]]*/  0;
</script>
<script>
    let createModal = $("#create_video_template").modal("添加黑名单", function () {
        listHandler.create();
    });
    $(function () {
        //初始化分页
        var pageinate = new hot.paging(".pagination", pageIndex, totalPages, 7);

        pageinate.init(function (p) {
            listHandler.search(p);
        });

    });
    let listHandler = {
        search: function (pageIndex) {
            $("input[name=pageIndex]").val(pageIndex);
            $("#searchForm").submit();
        },
        searchAll: function () {
            window.location.href = pageUri + "?type=" + blacklistType;
        },
        createModalShow: function () {
            let options = {
                btn: ["保存", "取消"]
            };
            createModal.show(function () {
            }, options);
        },
        create: function () {
            let mobile = $("#targetMobile").val();
            if (typeof keyword === "undefined" || keyword === "") {
                hot.tip.error("请输入目标用户手机号");
                return;
            }

            let requestData = {
                mobile: mobile,
                type: blacklistType
            };

            hot.ajax(apiUri + "/save", requestData, function (apiResult) {
                if (apiResult.resultCode === 2000) {
                    hot.tip.success("保存成功", function () {
                        window.location.reload();
                    }, 200)
                } else {
                    hot.tip.error("保存失败--" + apiResult.resultMsg);
                }
            }, function () {
            }, "post", 100);
        },
        delete(id) {
            hot.confirm("是否移除黑名单？", function () {
                hot.ajax(apiUri + "/delete", {id: id}, function (apiResult) {
                    if (apiResult.resultCode === 2000) {
                        hot.tip.success("移除成功", function () {
                            window.location.reload();
                        }, 200);
                    } else {
                        hot.tip.error("移除失败");
                    }
                }, function () {
                }, "get", 100);
            });
        }
    }
</script>
</body>
</html>